package com.wutong.teacher_server.config;

import com.wutong.teacher_server.task.HelloTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;

import java.util.Date;

//@Configuration
public class QuartzConfig {
    @Bean
    public JobDetailFactoryBean myJobDetail(){
        JobDetailFactoryBean factoryBean = new JobDetailFactoryBean();
        factoryBean.setJobClass(HelloTask.class);
        return factoryBean;
    }
    @Bean
    public SimpleTriggerFactoryBean myTrigger(){
        SimpleTriggerFactoryBean factoryBean = new SimpleTriggerFactoryBean();
        factoryBean.setJobDetail(myJobDetail().getObject());
        Date date = new Date((new Date().getTime() + 60));
        factoryBean.setStartTime(date);
        factoryBean.setRepeatInterval(100);
        factoryBean.setRepeatCount(3);
        return factoryBean;
    }
    @Bean
    public SchedulerFactoryBean schedulerFactoryBean(SimpleTriggerFactoryBean simpleTriggerFactoryBean){
        SchedulerFactoryBean factoryBean = new SchedulerFactoryBean();
        factoryBean.setTriggers(simpleTriggerFactoryBean.getObject());

        return factoryBean;
    }

}
